#ifndef __VTOR_HEAP_H__
#define __VTOR_HEAP_H__


#ifdef __cplusplus
extern "C" {
#endif

#include "vtor_elec_module_config.h"
//#include "vtor_printf.h"

#ifdef __VTOR_HEAP__

typedef struct VtorHeapNodeStruct
{
	struct VtorHeapNodeStruct* nextHeapNode;
	int heapLen;
	int heapHeadMagicNumber;
}VtorHeapNode;

// 禁用调试打印
#define VtorHeapDebug(...)
// vs平台直接使用c库
//#define VtorHeapDebug(...)				printf(__VA_ARGS__)
// 使用vtorprintf打印
//#define VtorHeapDebug(...)					VtorDebugPrintf(__VA_ARGS__)

// 对齐，
#define VTOR_HEAP_ALIGNED	4

#define VtorHeapMallocNumber				0xa11ca11c // malloc 代表给程序员
#define VtorHeapFreeNumber					0xfeeefeee // free 代表属于操作系统



#define VtorHeap_Init(heapBuf, heapSize)	VtorHeapx_Init(0, heapBuf, heapSize)
#define VtorHeap_Malloc(userSize)			VtorHeapx_Malloc(0, userSize)
#define VtorHeap_Free(heapBuf)				VtorHeapx_Free(0, heapBuf)
#define VtorHeap_Realloc(heapBuf, newsize)	VtorHeapx_Realloc(0, heapBuf, newsize)

#define VtorHeap0_Init(heapBuf, heapSize)	VtorHeapx_Init(0, heapBuf, heapSize)
#define VtorHeap0_Malloc(userSize)			VtorHeapx_Malloc(0, userSize)
#define VtorHeap0_Free(heapBuf)				VtorHeapx_Free(0, heapBuf)
#define VtorHeap0_Realloc(heapBuf, newsize)	VtorHeapx_Realloc(0, heapBuf, newsize)

#define VtorHeap1_Init(heapBuf, heapSize)	VtorHeapx_Init(1, heapBuf, heapSize)
#define VtorHeap1_Malloc(userSize)			VtorHeapx_Malloc(1, userSize)
#define VtorHeap1_Free(heapBuf)				VtorHeapx_Free(1, heapBuf)
#define VtorHeap1_Realloc(heapBuf, newsize)	VtorHeapx_Realloc(1, heapBuf, newsize)

#define VtorHeap2_Init(heapBuf, heapSize)	VtorHeapx_Init(2, heapBuf, heapSize)
#define VtorHeap2_Malloc(userSize)			VtorHeapx_Malloc(2, userSize)
#define VtorHeap2_Free(heapBuf)				VtorHeapx_Free(2, heapBuf)
#define VtorHeap2_Realloc(heapBuf, newsize)	VtorHeapx_Realloc(2, heapBuf, newsize)




void VtorHeap_SetHeadNode(int heapIdx, void* heapBuf);
VtorHeapNode* VtorHeap_GetHeadNode(int heapIdx);

VtorHeapNode* VtorHeapx_Init(int heapIdx, void* heapBuf, int heapSize);
void VtorHeap_PrintInfo(int heapIdx);
void* VtorHeapx_Malloc(int heapIdx, int userSize);
void VtorHeapx_Free(int heapIdx, void* heapBuf);
void* VtorHeapx_Realloc(int heapIdx, void* heapBuf, int newsize);

#endif // __VTOR_HEAP__


#ifdef __cplusplus
}
#endif


#endif

